﻿using Microsoft.OpenApi.Models;

namespace Git.Storage.WebApi.Extensions.SwaggerExtend
{
    /// <summary>
    /// 自定义Swagger 
    /// </summary>
    public static class SwaggerExt
    {
        /// <summary>
        /// 自定以Swagger中间件
        /// </summary>
        /// <param name="services"></param>
        public static void AddSwaggerGanSetup(this IServiceCollection services)
        {
            services.AddSwaggerGen(option =>
            {
                //添加版本描述信息
                typeof(ApiVersions).GetEnumNames().ToList().ForEach(version =>
                {
                    option.SwaggerDoc(version, new OpenApiInfo()
                    {
                        Title = $"老亚瑟仓储管理系统PDA接口",
                        Version = version,
                        Description = $"通用版本CoreApi版本{version}"
                    });

                });
                //AppContext.BaseDirectory:获取运行目录路径
                var file = Path.Combine(AppContext.BaseDirectory, "Git.Storage.WebApi.xml");
                //true:是否显示xml注释
                option.IncludeXmlComments(file, true);
            });



        }

        /// <summary>
        ///  使用Swagger中间件
        /// </summary>
        /// <param name="application"></param>
        public static void UseSwaggerUISetUp(this WebApplication application)
        {
            application.UseSwagger();  
            application.UseSwaggerUI(option =>
            {
                typeof(ApiVersions).GetEnumNames().ToList().ForEach(version =>
                {
                    option.SwaggerEndpoint($"/swagger/{version}/swagger.json",
                      $"高级版实战Api第【{version}】版本");
                });
            });
        }
    }
}
